package com.atguigu.srb.core.controller.api;


import com.atguigu.srb.core.pojo.entity.Lend;
import com.atguigu.srb.core.pojo.vo.LendDetailVO;
import com.atguigu.srb.core.pojo.vo.LendSearchVO;
import com.atguigu.srb.core.service.LendService;
import com.atguigu.srb.result.ResponseVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * <p>
 * 标的准备表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2024-04-15
 */

@Api(tags = "投资人操作的标的 接口")
@RestController
@RequestMapping("/api/core/lend")
public class ApiLendController {
    @Resource
    private LendService lendService;

    @ApiOperation("投标")
    @GetMapping("invest/{investAmount}/{lendId}")
    public ResponseVo invest(@PathVariable("investAmount") BigDecimal investAmount,
                             @PathVariable("lendId") Long lendId,@RequestHeader("token") String token){
        String formStr = lendService.invest(token,investAmount,lendId);
        return ResponseVo.ok().addData("item",formStr);
    }

    @ApiOperation("计算收益")
    @GetMapping("/income/{amount}/{yearRate}/{period}/{returnMethod}")
    public ResponseVo getIncome(@PathVariable("amount")BigDecimal amount,
                                @PathVariable("yearRate")BigDecimal yearRate,
                                @PathVariable("period")Integer period,
                                @PathVariable("returnMethod")Integer returnMethod){
        BigDecimal income = lendService.getIncome(amount,yearRate,period,returnMethod);
        return ResponseVo.ok().addData("item",income);
    }

    @ApiOperation("查询标的详情")
    @GetMapping("/detail/{lendId}")
    public ResponseVo getLendDetailById(@PathVariable("lendId") Long lendId){
        LendDetailVO lendDetailVo = lendService.getLendDetailById(lendId);
        return ResponseVo.ok().addData("item", lendDetailVo);
    }
    @ApiOperation("查询标的列表 分页带条件")
    @GetMapping("list/{pageNum}/{pageSize}")
    public ResponseVo getLendListWithCondition(LendSearchVO lendSearchVO, @PathVariable Integer pageNum,
                                               @PathVariable Integer pageSize) {
        Page<Lend> page = lendService.getLendListWithCondition(lendSearchVO, pageNum, pageSize);
        return ResponseVo.ok().addData("page", page);
    }
}

